package chen.web.controller.forum.model;

import chen.web.MyContextProvider;
import chen.web.util.jdbc.wrapper.QueryInfo;

public class Timer {

	/**
	 * 本次请求的耗时，单位：毫秒
	 * @return
	 */
	public int getProcessTime(){
		long startTime = (Long)MyContextProvider.getMyContext().getAttribute(chen.web.util.Timer.Process_Start_Time_Attribute_Name);
		return (int)((System.nanoTime() - startTime)/1000000);
	}
	
	/**
	 * 本次请求数据库操作的耗时，单位：毫秒
	 * @return
	 */
	public int getQueryTime(){
		QueryInfo info = (QueryInfo)MyContextProvider.getMyContext().getAttribute(chen.web.util.Timer.Jdbc_Query_Info_Context_Attribute_Name);
		return (int)(info.getQueryTime()/1000000);
	}
	
	/**
	 * 本次请求数据操作次数次数
	 * @return
	 */
	public int getQueryCount(){
		QueryInfo info = (QueryInfo)MyContextProvider.getMyContext().getAttribute(chen.web.util.Timer.Jdbc_Query_Info_Context_Attribute_Name);
		return info.getQueryCount();
	}
}
